﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OpenCvApplication
{
    public partial class FrmBase : Form
    {
        public FrmBase()
        {
            InitializeComponent();
        }

        protected void AddFormToContainer(Control parent,Form form)
        {
            if(parent == null || form==null) 
                return;

            form.TopLevel=false;
            form.Dock = DockStyle.Fill;
            form.Parent = parent;
            parent.Controls.Add(form);
            form.Show();
        }

        private string _imageExtension;
        /// <summary>
        /// 用于选取图像时过滤文件
        /// </summary>
        public string ImageExtension
        {
            get
            {
                if (string.IsNullOrEmpty(_imageExtension))
                {
                    string temp = String.Join(";", ImageExtensions.Select(t => $"*{t}"));
                    _imageExtension = $"Image Files ({temp})|{temp}";
                }
                return _imageExtension;
            }
        }
        /// <summary>
        /// 文件扩展名
        /// </summary>
        public virtual string[] ImageExtensions { get; } = { ".bmp", ".jpg", ".jpeg", ".png" };
        /// <summary>
        /// 选择文件
        /// </summary>
        /// <param name="fileFilterExtension">过滤文件</param>
        /// <returns></returns>
        public string SelectFile(string fileFilterExtension = "")
        {
            using OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = fileFilterExtension;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string selectedFile = openFileDialog.FileName;
                return selectedFile;
            }
            return string.Empty;
        }

    }
}
